Title
import pandas as pd
import altair as alt
df = pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-11-13/malaria_deaths.csv')
#df.head()
df.columns = ['name', 'ISO3166-1-Alpha-3','Year','Death_Rate']
#df['Year'] = pd.to_datetime(df['Year'], format='%Y')
country_info = pd.read_csv("https://raw.githubusercontent.com/datasets/country-codes/master/data/country-codes.csv",dtype = 'str')
df_new = df[df['ISO3166-1-Alpha-3'].isin(country_info['ISO3166-1-Alpha-3'])]
df_new.head()
df_final = pd.merge(df_new, country_info , on = 'ISO3166-1-Alpha-3', how = 'left')
df_final = df_final[['Year','Death_Rate','ISO3166-1-numeric']]
df_final.head()
alt.data_transformers.disable_max_rows()
countries = alt.topo_feature(data.world_110m.url, 'countries')
slider = alt.binding_range(
step=1,
min=1990,
max=2016
)
select_date = alt.selection_single(
name="slider",
fields=['Year'],
bind=slider,
)
from vega_datasets import data
alt.data_transformers.disable_max_rows()
countries = alt.topo_feature(data.world_110m.url, 'countries')
slider = alt.binding_range(
step=1,
min=1990,
max=2016
)
select_date = alt.selection_single(
name="slider",
fields=['Year'],
bind=slider,
)
alt.Chart(df_final).mark_geoshape()\
.encode(color='Death_Rate:Q')\
.add_selection(select_date)\
.transform_filter(select_date)\
.transform_lookup(
lookup='ISO3166-1-numeric',
from_=alt.LookupData(countries, key='id', fields=["type", "properties", "geometry"])
)\
.project('orthographic')\
.properties(
width=400,
height=300,
title='Malaria Death Rate (per 100,000 people) '
)
df_final['Year'] = pd.to_datetime(df_final['Year'], format='%Y')
country_list = df_final['ISO3166-1-numeric'].dropna().unique()
country_list = country_list.tolist()
dropdown = alt.binding_select(
options = country_list
)
select_country = alt.selection_single(
name="dropdown",
fields=['ISO3166-1-numeric'],
bind = dropdown,
)
alt.Chart(df_final).mark_line().encode(
x='Year',
y='Death_Rate',
).add_selection(
select_country
).transform_filter(select_country)
df1 = pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-11-13/malaria_inc.csv')
df1.columns = ['name', 'ISO3166-1-Alpha-3','Year','Incidence_Rate']
df1_new = df1[df1['ISO3166-1-Alpha-3'].isin(country_info['ISO3166-1-Alpha-3'])]
df1_new.head()
df1_final = pd.merge(df1_new, country_info , on = 'ISO3166-1-Alpha-3', how = 'left')
df1_final = df1_final[['Year','Incidence_Rate','ISO3166-1-numeric']]
df1_final.head()
alt.data_transformers.disable_max_rows()
countries = alt.topo_feature(data.world_110m.url, 'countries')
slider1 = alt.binding_range(
step=5,
min=2000,
max=2015
)
select_date1 = alt.selection_single(
name="slider",
fields=['Year'],
bind=slider1,
)
from vega_datasets import data
alt.Chart(df1_final).mark_geoshape()\
.encode(color='Incidence_Rate:Q')\
.add_selection(select_date1)\
.transform_filter(select_date1)\
.transform_lookup(
lookup='ISO3166-1-numeric',
from_=alt.LookupData(countries, key='id', fields=["type", "properties", "geometry"])
)\
.project('orthographic')\
.properties(
width=400,
height=300,
title='Malaria Incidence Rate (per 1,000 people) '
)
df2 = pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-11-13/malaria_deaths_age.csv')
df2.columns = ['index','name', 'ISO3166-1-Alpha-3','Year','Age_Group','Death_Rate']
df2_new = df2[df2['ISO3166-1-Alpha-3'].isin(country_info['ISO3166-1-Alpha-3'])]
df2_new.head()
df2_final = pd.merge(df2_new, country_info , on = 'ISO3166-1-Alpha-3', how = 'left')
df2_final = df2_final[['Year','Death_Rate','ISO3166-1-numeric','Age_Group']]
df2_final.head()
df2_final['Year'] = pd.to_datetime(df2_final['Year'], format='%Y')
country_list2 = df2_final['ISO3166-1-numeric'].dropna().unique()
country_list2 = country_list2.tolist()
dropdown2 = alt.binding_select(
options = country_list2
)
select_country2 = alt.selection_single(
name="dropdown",
fields=['ISO3166-1-numeric'],
bind = dropdown2,
)
alt.Chart(df2_final).mark_point().encode(
x='Year',
y='Death_Rate',
color = 'Age_Group'
).add_selection(
select_country2
).transform_filter(select_country2)